package com.pt.manage.service.impl;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

import com.pt.common.core.domain.AjaxResult;
import com.pt.common.utils.SecurityUtils;
import com.pt.common.utils.uuid.code;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.pt.manage.mapper.TrainingcourseMapper;
import com.pt.manage.domain.Trainingcourse;
import com.pt.manage.service.ITrainingcourseService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 课程管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-02-21
 */
@Service
public class TrainingcourseServiceImpl implements ITrainingcourseService 
{
    @Autowired
    private TrainingcourseMapper trainingcourseMapper;

    /**
     * 查询课程管理
     * 
     * @param CourseID 课程管理主键
     * @return 课程管理
     */
    @Override
    public Trainingcourse selectTrainingcourseByCourseID(Long CourseID)
    {

        return trainingcourseMapper.selectTrainingcourseByCourseID(CourseID);
    }

    /**
     * 查询课程管理列表
     * 
     * @param params 课程管理
     * @return 课程管理
     */
    @Override
    public List<Trainingcourse> selectTrainingcourseList(Map params)
    {
        return trainingcourseMapper.selectTrainingcourseList(params);
    }
    /**
     * 查询课程管理列表
     *
     * @param params 课程管理
     * @return 课程管理
     */
    @Override
    public List<Trainingcourse> selectStudentcourseList(Map params)
    {
        return trainingcourseMapper.selectStudentcourseList(params);
    }


    /**
     * 新增课程管理
     * 
     * @param trainingcourse 课程管理
     * @return 结果
     */
    @Transactional
    @Override
    public int insertTrainingcourse(Trainingcourse trainingcourse)
    {
        HashSet<String> CodeList = trainingcourseMapper.selectCode();
        trainingcourse.setCourseCode(code.generateUniqueCode(CodeList));
        int resultCourse = trainingcourseMapper.insertTrainingcourse(trainingcourse);
        int resultTeacher = trainingcourseMapper.insertCourseTeacher(trainingcourse.getCourseID(),SecurityUtils.getUserId());
        if(resultCourse > 0&&resultTeacher > 0) return resultCourse;
        return 0;
    }

    /**
     * 修改课程管理
     * 
     * @param trainingcourse 课程管理
     * @return 结果
     */
    @Transactional
    @Override
    public int updateTrainingcourse(Trainingcourse trainingcourse)
    {
        return trainingcourseMapper.updateTrainingcourse(trainingcourse);
    }

    /**
     * 批量删除课程管理
     * 
     * @param CourseIDs 需要删除的课程管理主键
     * @return 结果
     */
    @Override
    public int deleteTrainingcourseByCourseIDs(Long[] CourseIDs)
    {
        return trainingcourseMapper.deleteTrainingcourseByCourseIDs(CourseIDs);
    }

    /**
     * 删除课程管理信息
     * 
     * @param CourseID 课程管理主键
     * @return 结果
     */
    @Override
    public int deleteTrainingcourseByCourseID(Long CourseID)
    {
        return trainingcourseMapper.deleteTrainingcourseByCourseID(CourseID);
    }

    @Override
    public int insertStudentCourse(Map params) {
        return trainingcourseMapper.insertStudentcourse(params);
    }
}
